﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
using UnityEngine.Profiling;
partial class MyRender
{

#if UNITY_EDITOR

    private string _sampleName;
    public string SampleName
    {
        set
        {
            _sampleName = value;
        }
        get
        {
            return _sampleName;
        }
    }


    static ShaderTagId unlitShaderTagId = new ShaderTagId("SRPDefaultUnlit");
    static ShaderTagId litShaderTagId = new ShaderTagId("CustomLit");
    static ShaderTagId[] unSupportShaderTagIds =
    {
        new ShaderTagId("Always"),
        new ShaderTagId("ForwardBase"),
        new ShaderTagId("PrepassBase"),
        new ShaderTagId("Vertex"),
        new ShaderTagId("VertexLMRGBM"),
        new ShaderTagId("VertexLM")
    };
    static Material _errMat;

    partial void DrawUnsupportShaders()
    {
        if (_errMat == null)
        {
            _errMat = new Material(Shader.Find("Hidden/InternalErrorShader"));
        }

        var drawSetting = new DrawingSettings
        (
            unSupportShaderTagIds[0], new SortingSettings(_cam)
        )
        {
            overrideMaterial = _errMat
        };


        var filiterSettings = FilteringSettings.defaultValue;

        for (int n = 1; n < unSupportShaderTagIds.Length; n++)
        {
            drawSetting.SetShaderPassName(n, unSupportShaderTagIds[n]);
        }
        _context.DrawRenderers(_cullResults, ref drawSetting, ref filiterSettings);
    }

    partial void DrawGizmos()
    {
        if (Handles.ShouldRenderGizmos())
        {
            _context.DrawGizmos(_cam, GizmoSubset.PreImageEffects);
            _context.DrawGizmos(_cam, GizmoSubset.PostImageEffects);
        }
    }

    partial void PrepareForSceneView()
    {
        if(_cam.cameraType == CameraType.SceneView)
        {
            ScriptableRenderContext.EmitWorldGeometryForSceneView(_cam);
        }
    }

    partial void PrepareBuffer()
    {
        Profiler.BeginSample("Editor Only");
        _cmd.name = _cam.name;
        _sampleName = _cam.name;
        Profiler.EndSample();
    }


#endif

    partial void DrawUnsupportShaders();
    partial void DrawGizmos();
    partial void PrepareForSceneView();
    partial void PrepareBuffer();
    
}


